const Router = require('koa-router')

const router = new Router({ prefix: '/topics' })

const {
  find,
  findById,
  create,
  update,
  listFollowers,
  listQuestions
} = require('../controllers/topics')

const auth = require('../middleware/auth')
const { checkTopicExist } = require('../middleware/exist')

// 获取（整体）
router.get('/', find)

// 获取（单一）
router.get('/:id', checkTopicExist, findById)

// 新增
router.post('/', auth, create)

// 更新
router.patch('/:id', auth, checkTopicExist, update)

// 获取话题粉丝
router.get('/:id/followers', checkTopicExist, listFollowers)

// 获取话题下的问题
router.get('/:id/questions', checkTopicExist, listQuestions)

module.exports = router
